package com.tarena.lbs.business.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.business.pojo.param.StoreParam;
import com.tarena.lbs.business.pojo.param.UserLocationParam;
import com.tarena.lbs.business.pojo.query.AreaStoreQuery;
import com.tarena.lbs.business.pojo.query.StoreChainQuery;
import com.tarena.lbs.business.pojo.query.StoreQuery;
import com.tarena.lbs.business.pojo.vo.StoreChainVO;
import com.tarena.lbs.business.pojo.vo.StoreVO;
import com.tarena.lbs.business.servcie.StoreService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Tag(name = "店铺相关功能接口")
@RestController
@Slf4j
public class StoreController {
    @Autowired
    private StoreService storeService;



    @Operation(summary = "查询店铺列表")
    @PostMapping("/admin/basic/store/getAll")
    public Result<PageResult<StoreVO>> pageList(@RequestBody StoreQuery query)
        throws BusinessException {
        log.info("查询店铺列表参数:{}", query);

        PageResult<StoreVO> pageResult = storeService.pageList(query);
        return new Result<>(pageResult);
    }

    /**
     * 新增店铺
     * @param param
     * @return
     * @throws BusinessException
     */
    @Operation(summary = "新增店铺")
    @PostMapping("/admin/basic/store/add")
    public Result<Void> save(@RequestBody StoreParam param)
        throws BusinessException {
        log.info("新增店铺参数:{}", param);
        storeService.saveStore(param);
        return Result.success();
    }

    //查询 属于当前登录用户 所属商家 和满足区域条件的店铺列表
    @Operation(summary = "查询区域下的店铺列表")
    @PostMapping("/admin/basic/store/getStoreByCity")
    public Result<PageResult<StoreVO>> getStoreByCity(@RequestBody AreaStoreQuery query)
        throws BusinessException {
        log.info("查询区域下的店铺列表参数:{}", query);
        PageResult<StoreVO> pageResult = storeService.getStoreByCity(query);
        return new Result<>(pageResult);
    }
    /**
     * 店铺状态切换
     * @param id
     * @return
     * @throws BusinessException
     */
    @Operation(summary = "店铺状态切换")
    @PutMapping("/admin/basic/store/enable/{id}")
    public Result<Void> enable(@PathVariable Integer id)
        throws BusinessException{
        log.info("店铺状态切换参数:{}", id);
        storeService.enable(id);
        return Result.success();
    }
    ///admin/basic/store/disable/1
    @Operation(summary = "店铺状态切换")
    @PutMapping("/admin/basic/store/disable/{id}")
    public Result<Void> disable(@PathVariable Integer id)
            throws BusinessException{
        log.info("店铺状态切换参数:{}", id);
        storeService.enable(id);
        return Result.success();
    }

    //手机小程序定位上报
    @Operation(summary = "手机小程序定位上报")
    @PostMapping("/basic/store/location")
    public Result<Void> location(@RequestBody UserLocationParam param)
        throws BusinessException{
        log.info("手机小程序定位上报参数:{}", param);
        storeService.location(param);
        return Result.success();
    }
    //http://localhost:19999/admin/basic/store/1
    @Operation(summary = "编辑店铺")
    @GetMapping("/admin/basic/store/{id}")
    public Result<StoreVO> edit(@PathVariable Integer id)
        throws BusinessException{
        log.info("编辑店铺参数:{}", id);
        StoreVO storeVO = storeService.selectByStoreId(id);
        return new Result<>(storeVO);
    }
    //http://localhost:19999/admin/basic/store/delete/1
    @Operation(summary = "删除店铺")
    @DeleteMapping("/admin/basic/store/delete/{id}")
    public Result<Void> delete(@PathVariable Integer id){
        log.info("删除店铺参数:{}", id);
        storeService.delete(id);
        return Result.success();
    }

    //http://localhost:19999/admin/basic/chain/getAll 二维码管理
    @Operation(summary = "二维码管理")
    @PostMapping("/admin/basic/chain/getAll")
    public Result<PageResult<StoreChainVO>> getAll(@RequestBody StoreChainQuery query) throws BusinessException {
        log.info("二维码管理参数:{}", query);
        PageResult<StoreChainVO> pageResult = storeService.pageList(query);
        return new Result<>(pageResult);
    }

    //未完成无法获取链接
    //http://localhost:19999/admin/basic/chain/disable/54988801
    @Operation(summary = "店铺状态切换")
    @PutMapping("/admin/basic/chain/disable/{id}")
    public Result<Void> disableChain(@PathVariable Integer id)
            throws BusinessException{
        log.info("店铺状态切换参数:{}", id);
        return Result.success();
    }

    @Operation(summary = "店铺状态切换")
    @PutMapping("/admin/basic/chain/enable/{id}")
    public Result<Void> enableChain(@PathVariable Integer id)
            throws BusinessException{
        log.info("店铺状态切换参数:{}", id);
        return Result.success();
    }

}
